import { categoryDate } from "../../api/category";

Page({
  data: {
    categoryList: [],
    childrenList: [],
    activeIndex: 0,
  },

  async getCategoryData() {
    const _this = this;
    const res = await categoryDate();
    // console.log("分类=》", res.data.data);
    if (res.data.data.length > 0) {
      _this.setData({
        categoryList: res.data.data,
        childrenList: res.data.data[0].children,
      });
    }
  },

  onLoad() {
    this.getCategoryData();
  },

  categoryRight(event) {
    const _this = this;
    const { index } = event.currentTarget.dataset;
    // console.log("值=》", index);
    _this.setData({
      activeIndex: index,
      childrenList: this.data.categoryList[index].children,
    });
  },
});
